<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>推荐导购</title>
<link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
<script src="../res/layui/layui.js"></script>
</head>

<body>
	<form id='form-xiugai' class="layui-form" action=""
		style="width: 60%; margin-top: 10px;" lay-filter="form-xiugai">
	

		
<div class="layui-form-item">
			<label class="layui-form-label">导购排序</label>
			<div class="layui-input-block">
				<input type="text" name="dgsort" placeholder=""
					autocomplete="off" class="layui-input">
			</div>
		</div>

       <div style="display: none">
			<input type="text" name="dgsort" placeholder="" autocomplete="off"
				class="layui-input">
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="xiugai-submit">修改</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</body>

<script>
	layui.use([ 'layer', 'form' ], function() {
		var $ = layui.$ //jquery
		, layer = layui.layer //弹层
		, form = layui.form //表单	

		//获取共享数据ids
		var ids = layui.sessionData("ids");
		
		var active = {
			loadData : function() {
				//去后台查询数据
				$.post("http://localhost:8080/g4/daogou/query", {
					//从本地拿学生id查询学生  没有则   查询id为101的学生（调试用）
					pid : ids["pid"] ? ids["pid"] : 101
				}, function(result) {
					if (result.code === '0') {
						form.val("form-xiugai", result.data);

					} else {
						layer.alert(result.msg);
					}
				}, "json");
			}
		}
		//加载班级下拉框

		$.post("http://localhost:8080/g4/daogou/selsctOpResults", {},
				function(result) {
					if (result.code === '0') {
						$.each(result.data, function(index, item) {
							$('#categoryid').append(
									new Option(item.value, item.view));// 下拉菜单里添加元素
						});
						form.render('select');
						active.loadData();
					} else {
						layer.alert(result.msg);
					}
				}, "json"
				
		);

		form.on('submit("xiugai-submit")', function(data) {
			var str = $("#form-xiugai").serialize();
			$.post("http://localhost:8080/g4/daogou/update", str,
					function(result) {
						if (result.code === '0') {
							parent.layui.$("#shousuo").click();
							parent.layer.alert(result.msg);
							
							//关闭自身
							var index = parent.layer
									.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index);//再执行关闭
						
							
						} else {
							layer.alert(result.msg);
						}
					}, "json");
			return false;
		});
	});
</script>

</html>
